﻿using System;
using System.Collections.Generic;
using HK.Core.Common.Data;
using HK.Core.Common.Protocol;
using HK.Core.Common.Protocol.Data;
using HK.Core.Serializable.Data;
using HK.Core.Utils;

namespace HK.Core.Serializable.Protocol.Data
{
    
    /// <summary>
    /// 序列化资产文件操作选项
    /// </summary>
    [Flags]
    public enum SAssetOperateOptions
    {
        
        /// <summary>
        /// 无
        /// </summary>
        None = 0x00000000,
        /// <summary>
        /// 清空
        /// </summary>
        Clear = 0x00000001,
        
        /// <summary>
        /// 强制清空 - Json
        /// <para>* 不加密</para>
        /// </summary>
        ForceClearJson = 0x00000002,
        
        /// <summary>
        /// 强制清空 - Json
        /// <para>* 加密 : Aes</para>
        /// </summary>
        ForceClearJsonAes = 0x00000004,
        
        /// <summary>
        /// 强制清空 - Binary
        /// <para>* 加密 : Des</para>
        /// </summary>
        ForceClearJsonDes = 0x00000008,
        
        /// <summary>
        /// 强制清空 - Token - Hs512
        /// </summary>
        ForceClearJsonAll = ForceClearJson | ForceClearJsonAes | ForceClearJsonDes,
        
        /// <summary>
        /// 强制清空 - Token - Hs256
        /// </summary>
        ForceClearTokenHs256 = 0x00000010,
        
        /// <summary>
        /// 强制清空 - Token - Hs384
        /// </summary>
        ForceClearTokenHs384 = 0x00000020,
        
        /// <summary>
        /// 强制清空 - Token - Hs512
        /// </summary>
        ForceClearTokenHs512 = 0x00000040,
        
        /// <summary>
        /// 强制清空 - Token - Hs512
        /// </summary>
        ForceClearTokenAll = ForceClearTokenHs256 | ForceClearTokenHs384 | ForceClearTokenHs512,
        
        /// <summary>
        /// 强制清空 - Binary
        /// <para>* 不加密</para>
        /// </summary>
        ForceClearBinary = 0x00000080,
        
        /// <summary>
        /// 强制清空 - Binary
        /// <para>* Aes</para>
        /// </summary>
        ForceClearBinaryAes = 0x00000100,
        
        /// <summary>
        /// 强制清空 - Binary
        /// <para>* Des</para>
        /// </summary>
        ForceClearBinaryDes = 0x00000200,
        
        /// <summary>
        /// 强制清空 - Binary - All
        /// </summary>
        ForceClearBinaryAll = ForceClearBinary | ForceClearBinaryAes | ForceClearBinaryDes,
            
        /// <summary>
        /// 全类型强制清空
        /// </summary>
        ForceClearAll = ForceClearJsonAll | ForceClearTokenAll | ForceClearBinaryAll,
        
        /// <summary>
        /// 导入 - Json
        /// <para>* 不加密</para>
        /// </summary>
        ImportJson = 0x00000400,
        
        /// <summary>
        /// 导入 - Json
        /// <para>* 加密 : Aes</para>
        /// </summary>
        ImportJsonAes = 0x00000800,
        
        /// <summary>
        /// 导入 - Json
        /// <para>* 加密 : Des</para>
        /// </summary>
        ImportJsonDes = 0x00001000,
            
        /// <summary>
        /// 导入 - Json - All
        /// </summary>
        ImportJsonAll = ImportJson | ImportJsonAes | ImportJsonDes,
        
        /// <summary>
        /// 导入 - Token - Hs256
        /// </summary>
        ImportTokenHs256 = 0x00002000,
        
        /// <summary>
        /// 导入 - Token - Hs384
        /// </summary>
        ImportTokenHs384 = 0x00004000,
            
        /// <summary>
        /// 导入 - Token - Hs512
        /// </summary>
        ImportTokenHs512 = 0x00008000,
            
        /// <summary>
        /// 导入 - Token - All
        /// </summary>
        ImportTokenAll = ImportTokenHs256 | ImportTokenHs384 | ImportTokenHs512,
        
        /// <summary>
        /// 导入 - Binary
        /// <para>* 不加密</para>
        /// </summary>
        ImportBinary = 0x00010000,
        
        /// <summary>
        /// 导入 - Binary
        /// <para>* Aes</para>
        /// </summary>
        ImportBinaryAes = 0x00020000,
        
        /// <summary>
        /// 导入 - Binary
        /// <para>* Des</para>
        /// </summary>
        ImportBinaryDes = 0x00040000,
        
        /// <summary>
        /// 导入 - Binary - All
        /// </summary>
        ImportBinaryAll = ImportBinary | ImportBinaryAes | ImportBinaryDes,
        
        /// <summary>
        /// 全类型
        /// </summary>
        ImportAll = ImportJsonAll | ImportTokenAll | ImportBinaryAll,
            
        /// <summary>
        /// 导出 - Json
        /// <para>* 不加密</para>
        /// </summary>
        ExportJson = 0x00080000,
        
        /// <summary>
        /// 导出 - Json
        /// <para>* 加密 : Aes</para>
        /// </summary>
        ExportJsonAes = 0x00100000,
        
        /// <summary>
        /// 导出 - Json
        /// <para>* 加密 : Des</para>
        /// </summary>
        ExportJsonDes = 0x00200000,
        
        /// <summary>
        /// 导出 - Json - All
        /// <para>* 加密 : Des</para>
        /// </summary>
        ExportJsonAll = ExportJson | ExportJsonAes | ExportJsonDes,
        
        /// <summary>
        /// 导出 - Token - Hs256
        /// </summary>
        ExportTokenHs256 = 0x00400000,
        
        /// <summary>
        /// 导出 - Token - Hs384
        /// </summary>
        ExportTokenHs384 = 0x00800000,
            
        /// <summary>
        /// 导出 - Token - Hs512
        /// </summary>
        ExportTokenHs512 = 0x01000000,
            
        /// <summary>
        /// 导出 - Token - Hs512
        /// </summary>
        ExportTokenAll = ExportTokenHs256 | ExportTokenHs384 | ExportTokenHs512,
        
        /// <summary>
        /// 导出 - Binary
        /// <para>* 不加密</para>
        /// </summary>
        ExportBinary = 0x02000000,
        
        /// <summary>
        /// 导出 - Binary
        /// <para>* Aes</para>
        /// </summary>
        ExportBinaryAes = 0x04000000,
            
        /// <summary>
        /// 导出 - Binary
        /// <para>* Des</para>
        /// </summary>
        ExportBinaryDes = 0x08000000,
        
        /// <summary>
        /// 导出 - Binary - All
        /// </summary>
        ExportBinaryAll = ExportBinary | ExportBinaryAes | ExportBinaryDes,
        
        /// <summary>
        /// 全类型导出
        /// </summary>
        ExportAll = ExportJsonAll | ExportTokenAll | ExportBinaryAll,
        
        /// <summary>
        /// 默认选项
        /// </summary>
        Default = Clear | ForceClearAll | ImportAll | ExportAll,
        
        /// <summary>
        /// 可帮助的
        /// <para>* 窗体右上角，工具栏处有帮助按钮</para>
        /// </summary>
        Helpful = 0x10000000,
        
        /// <summary>
        /// 窗体默认选项
        /// </summary>
        WindowDefaultOptions = Default | Helpful
    }

    /// <summary>
    /// 接口 : 序列化资产文件
    /// </summary>
    public interface ISAsset
    {
        /// <summary>
        /// 头部信息
        /// </summary>
        ISAssetHeader Header { get; }
        
        /// <summary>
        /// 版本
        /// </summary>
        ISAssetVersion Version { get; }
        
        /// <summary>
        /// 版本信息 - 短
        /// <para>* 版本格式 : Max.Mid.Min</para>
        /// </summary>
        string ShortVersion { get; }
        
        /// <summary>
        /// 版本信息 - All
        /// <para>* 版本格式 : Max.Mid.Min.Tag</para>
        /// </summary>
        string FullVersion { get; }
        
        /// <summary>
        /// 创建时间
        /// <para>* 格式 : YYYY/MM/DD HH:MM:SS</para>
        /// </summary>
        string CreateTimeTxt { get; }
        
        /// <summary>
        /// 更新时间
        /// <para>* 格式 : YYYY/MM/DD HH:MM:SS</para>
        /// </summary>
        string UpdateTimeTxt { get; }
        
        /// <summary>
        /// 静态文件标志位
        /// </summary>
        bool Static { get; }
        
        /// <summary>
        /// 数据目录
        /// </summary>
        string DataDir { get; }
        
        /// <summary>
        /// 路径
        /// </summary>
        string Path { get; }

#region CheckCode

        /// <summary>
        /// 校验码
        /// </summary>
        string CheckCode { get; }

        /// <summary>
        /// 生成校验码
        /// </summary>
        /// <param name="iMode">校验模式(默认:Md5)</param>
        /// <returns>校验码</returns>
        string GenCheckCode(CheckMode iMode = CheckMode.Md5);

#endregion

#region Operations

#region Import

        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="iOptions">选项</param>
        void Import(int iOptions);

        /// <summary>
        /// 导入 - Json
        /// <para>* 不加密</para>
        /// </summary>
        void ImportJson();

        /// <summary>
        /// 导入 - Json
        /// <para>* Aes</para>
        /// </summary>
        void ImportJsonAes();

        /// <summary>
        /// 导入 - Json
        /// <para>* Des</para>
        /// </summary>
        void ImportJsonDes();
        
        /// <summary>
        /// 导入 - Token
        /// <para>* Hs256</para>
        /// </summary>
        void ImportTokenHs256();
        
        /// <summary>
        /// 导入 - Token
        /// <para>* Hs384</para>
        /// </summary>
        void ImportTokenHs384();
        
        /// <summary>
        /// 导入 - Token
        /// <para>* Hs512</para>
        /// </summary>
        void ImportTokenHs512();
        
#endregion

#region Export

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="iOptions">选项</param>
        void Export(int iOptions);
        
        /// <summary>
        /// 导出 - All
        /// </summary>
        void ExportAll();

        /// <summary>
        /// 导出 - Json
        /// <para>* 不加密</para>
        /// </summary>
        void ExportJson();

        /// <summary>
        /// 导出 - Json
        /// <para>* Aes</para>
        /// </summary>
        void ExportJsonAes();

        /// <summary>
        /// 导出 - Json
        /// <para>* Des</para>
        /// </summary>
        void ExportJsonDes();
        
        /// <summary>
        /// 导出 - Token
        /// <para>* Hs256</para>
        /// </summary>
        void ExportTokenHs256();
        
        /// <summary>
        /// 导出 - Token
        /// <para>* Hs384</para>
        /// </summary>
        void ExportTokenHs384();
        
        /// <summary>
        /// 导出 - Token
        /// <para>* Hs512</para>
        /// </summary>
        void ExportTokenHs512();
        
#endregion

#region Clear

        /// <summary>
        /// 清除
        /// </summary>
        void Clear();
        
        /// <summary>
        /// 清除
        /// </summary>
        /// <param name="iOptions">选项</param>
        /// <param name="iForce">强制清空标志位</param>
        void Clear(int iOptions, bool iForce = false);
        
        /// <summary>
        /// 清除 - All
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearAll(bool iForce = false);
        
        /// <summary>
        /// 清除 - Json
        /// <para>* 不加密</para>
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearJson(bool iForce = false);
        
        /// <summary>
        /// 清除 - Json
        /// <para>* Aes</para>
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearJsonAes(bool iForce = false);
        
        /// <summary>
        /// 清除 - Json
        /// <para>* Des</para>
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearJsonDes(bool iForce = false);
        
        /// <summary>
        /// 清除 - Token
        /// <para>* Hs256</para>
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearTokenHs256(bool iForce = false);
        
        /// <summary>
        /// 清除 - Token
        /// <para>* Hs384</para>
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearTokenHs384(bool iForce = false);
        
        /// <summary>
        /// 清除 - Token
        /// <para>* Hs512</para>
        /// </summary>
        /// <param name="iForce">强制清空标志位</param>
        void ClearTokenHs512(bool iForce = false);

#endregion

#endregion

        /// <summary>
        /// 刷新
        /// </summary>
        void Refresh();

    }
    
    /// <summary>
    /// 接口 : 序列化资产文件
    /// </summary>
    /// <typeparam name="TBody">序列化文件Body数据类型</typeparam>
    public interface ISAsset<out TBody> : ISAsset where TBody : SAssetData, new()
    {
        
#region Data

        /// <summary>
        /// 序列化数据 - Body
        /// </summary>
        TBody Body { get; }

#endregion
        
    }

    /// <summary>
    /// 接口 : 序列化资产文件 - 列表
    /// </summary>
    /// <typeparam name="TBody">列表Body类型</typeparam>
    /// <typeparam name="TElement">列表Element类型</typeparam>
    public interface ISAssetList<out TBody, TElement> : ISAsset
        where TBody : SAssetListData<TBody, TElement>
        where TElement : JsonData, IListElement, IEquatable<TElement>
    {

#region Data
        
        /// <summary>
        /// 列表Body
        /// </summary>
        TBody Body { get; }
        
        /// <summary>
        /// 列表
        /// </summary>
        List<TElement> List { get; }

#endregion
            
    }
}
